
TOOL.Category		= "Render"
TOOL.Name			= "#Paint"
TOOL.Command		= nil
TOOL.ConfigName		= nil


TOOL.LeftClickAutomatic = true
TOOL.RightClickAutomatic = true
TOOL.RequiresTraceHit = true

TOOL.ClientConVar[ "decal" ] = "Blood"

local function PlaceDecal( Ent, Pos1, Pos2, decal )

	util.Decal( decal, Pos1, Pos2 )
	
	if ( CLIENT) then return end
	if ( Ent == NULL ) then return end
	if ( Ent:IsWorld() ) then return end
	if ( Ent:GetClass() != "prop_ragdoll" ) then return end

	local decal = 
		{ 
			decal, 
			Ent:WorldToLocal(Pos1), 
			Ent:WorldToLocal(Pos2) 
		}

	if not	Ent:GetTable().decals then Ent:GetTable().decals = {} end

	table.insert( Ent:GetTable().decals, 1, decal )

	//Trim decal table so only 50 decals are saved
	if #Ent:GetTable().decals > 50 then
		Ent:GetTable().decals[51] = nil
	end

end


function TOOL:LeftClick( trace )

	self:GetOwner():EmitSound("SprayCan.Paint")
	local decal	= self:GetClientInfo( "decal" )
	
	local Pos1 = trace.HitPos + trace.HitNormal
	local Pos2 = trace.HitPos - trace.HitNormal

	PlaceDecal( trace.Entity, Pos1, Pos2, decal )
	
	self:GetWeapon():SetNextPrimaryFire( CurTime() + 0.03 )
	
	return false
	
end

function TOOL:RightClick( trace )

	self:GetOwner():EmitSound("SprayCan.Paint")
	local decal	= self:GetClientInfo( "decal" )
	
	local Pos1 = trace.HitPos + trace.HitNormal
	local Pos2 = trace.HitPos - trace.HitNormal

	PlaceDecal( trace.Entity, Pos1, Pos2, decal )

	self:GetWeapon():SetNextSecondaryFire( CurTime() + 0.2 )

	return false
	
end
